package com.zhuimeng.provider;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.ProviderConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class ProviderApplication {
    public static void main(String[] args) throws Exception {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DubboConfiguration.class);
        context.start();
        System.in.read();
    }

    @Configuration
    @EnableDubbo(scanBasePackages = "com.zhuimeng.provider.service.impl")
    static class DubboConfiguration{
        @Bean //服务提供者信息配置
        public ProviderConfig providerConfig(){
            ProviderConfig providerConfig = new ProviderConfig();
            providerConfig.setTimeout(1000);
            return  providerConfig;
        }

        @Bean //应用信息配置
        public ApplicationConfig applicationConfig(){
            ApplicationConfig applicationConfig = new ApplicationConfig();
            applicationConfig.setName("dubbo-annotation-provider");
            return  applicationConfig;
        }

        @Bean //注册中心信息配置
        public RegistryConfig registryConfi(){
            RegistryConfig registryConfig = new RegistryConfig();
            registryConfig.setAddress("zookeeper://127.0.0.1:2181?timeout=1000000");
            registryConfig.setProtocol("zookeeper");
            return  registryConfig;
        }

        @Bean //协议配置
        public ProtocolConfig protocolConfig(){
            ProtocolConfig protocolConfig = new ProtocolConfig();
            protocolConfig.setName("dubbo");
            protocolConfig.setPort(20880);
            return  protocolConfig;
        }
    }
}
